/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-05-08 17:00:33
 * @LastEditTime : 2023-06-25 13:47:59
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Pages\Front\Common\Template\ProjectMap.jsx
 * @Description  :
 */
import './Scss/ProjectMap.scss'
import { useRef, useEffect } from 'react'
import { useEventEmitter, useRequest } from 'ahooks'
import { Initialization, InitializationData } from '../../../../Common/Mars3d/Initialization'
import { Http } from '../../../../Common/Api'
import { WebTemplateUrl } from './configuration'

export const ProjectMap001 = ({ uuid }) => {
    const Mars3dBox = useRef()
    const InitializationEvent = useEventEmitter()
    InitializationEvent.useSubscription(({ map, gra, uuid }) => {
        getScenesDetails({ url: `getScenesDetailsUuid`, path: [uuid] }).then(res => {
            InitializationData(map, gra, res, true)
        })
    })
    const { runAsync: getScenesDetails } = useRequest(Http, { manual: true })
    const { run: getScenes } = useRequest(Http, {
        manual: true,
        onSuccess: res => Initialization(res, Mars3dBox, InitializationEvent),
    })
    useEffect(() => {
        getScenes({ url: `getScenesID`, path: [uuid] })
    }, [getScenes, getScenesDetails, uuid])
    return (
        <div className="ProjectMap001">
            <div ref={Mars3dBox}></div>
            <img src={WebTemplateUrl + 'Mask.png'} alt="" />
        </div>
    )
}

export const ProjectMap002 = ({ uuid, data }) => {
    const Mars3dBox = useRef()
    const InitializationEvent = useEventEmitter()
    InitializationEvent.useSubscription(({ map, gra, uuid }) => {
        getScenesDetails({ url: `getScenesDetailsUuid`, path: [uuid] }).then(res => {
            InitializationData(map, gra, res, true)
            console.log(data)
            map.centerAt(data)
        })
    })
    const { runAsync: getScenesDetails } = useRequest(Http, { manual: true })
    const { run: getScenes } = useRequest(Http, {
        manual: true,
        onSuccess: res => Initialization(res, Mars3dBox, InitializationEvent),
    })
    useEffect(() => {
        getScenes({ url: `getScenesID`, path: [uuid] })
    }, [getScenes, getScenesDetails, uuid])
    return (
        <div className="ProjectMap001">
            <div ref={Mars3dBox}></div>
            {/* <img src={WebTemplateUrl + 'Mask.png'} alt="" /> */}
        </div>
    )
}
